define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_mydistributor(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"issue_type": "3","store": [' +
					'{"store_id": "001","store_name": "世达","credit_line": 5000,"brand": [' +
					'{"id": "001","name": "世达"},' +
					'{"id": "002","name": "博士"}' +
					'],"image": "img/upload/pro-img01.jpg","contact_name": "张三","contact_mobile": "18912345678","region": [' +
					'{"region": "上海"},' +
					'{"region": "北京"}],"store_cat": [' +
					'{"store_cat_name": "五金类"},' +
					'{"store_cat_name": "非五金类"}],"company_profile": "专营各类五金"}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';

				return JSON.parse(result);
			} else {
				return result;
			}

		}

		function get_data_delete(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};

		function get_data_credit_change(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_price_change(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_submit(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_grant(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		//返回信息
		return {
			//key, region, 这2个参数不要
			my_distributor: function(nPage,callback,calldone) {
				//				//post请求
				Http.post({
						method: 'member.agenter.getlist',
						pagelimit: 5,
						nPage: nPage
					},
					function(result) {
						//请求成功
						if(callback) {

							callback(get_data_mydistributor(result).result);
						}

					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
						if(calldone)
						calldone();
					}
				);

			},
			//删除我的代理商
			delete_agent: function(store_id, callback) {
				Http.post({
					method: 'member.agenter.delete',
					store_id: store_id
				}, function(result) {
					if(callback)
						callback(get_data_delete(result));
				}, function(e) {

				}, function() {

				});
			},
			//修改我的代理额度
			credit_change: function(store_id, credit_line, callback) {
				Http.post({
					method: 'member.credit.change',
					store_id: store_id,
					credit_line: credit_line
				}, function(result) {
					if(callback)
						callback(get_data_credit_change(result));
				}, function(e) {

				}, function() {

				});
			},
			//修改价格
			price_change: function(store_id, brand_id,is_price, callback) {
				Http.post({
					method: 'member.price.change',
					store_id: store_id,
					brand_id:brand_id,
					is_price: is_price
				}, function(result) {
					if(callback)
						callback(get_data_price_change(result));
				}, function(e) {

				}, function() {

				});
			},
			//拉黑
			get_submit: function(store_id, resean, callback) {
				Http.post({
						method: 'member.shielding.submit',
						store_id: store_id,
						resean: resean

					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_submit(result));
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//发送红包
			packets_grant: function(count, money, memo, rule,store, callback) {
				var targets = new Object();
				targets.stores = store;
				targets = JSON.stringify(targets);
				Http.post({
					method: 'member.packets.grant',
					count: count,
					money: money,
					memo: memo,
					rule: rule,
					type: 1,
					targets: targets
				}, function(result) {
					if(callback)
						callback(get_data_grant(result));
				}, function(e) {

				}, function() {

				});
			}
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Distributor", factory);
});